{% extends 'base.html' %}

{% block title %}
    仓库管理
{% endblock %}

{% block content %}
    <h1 class="mt-4">仓库列表</h1>
    <a href="{% url 'warehouse_create'%}" class="btn btn-primary mt-4">新建仓库</a>
    <table class="table table-striped">
        <thead>
            <tr>
            <th scope="col">ID</th>
            <th scope="col">仓库名称</th>
            <th scope="col">操作</th>
            </tr>
        </thead>
        <tbody>
            {% for warehouse in page_obj %}
            <tr>
                <td>{{ warehouse.id}}</td>
                <td>{{ warehouse.name}}</td>
                <td><a href="{% url 'warehouse_edit' warehouse.id %}" class="btn
                    btn-secondary btn-sm" >编辑</a>
                    <a href="{% url 'warehouse_delete' warehouse.id %}" class="btn
                    btn-danger btn-sm" >删除</a>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
<nav aria-label="Page navigation">
    <ul class="pagination">
        {% if page_obj.has_previous %}
            <li class="page-item">
                <a class="page-link" href="?page=1" aris-label="First">
                    <span aria-hidden="true">&laquo;&laquo;</span>
                </a>
            </li>
            <li class="page-item">
                <a class="page-link" href="?page={{ page_obj.previous_page_number }}" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
        {% endif %}
        {% for num in page_obj.paginator.page_range %}
            {% if page_obj.number == num %}
                <li class="page-item active">
                    <a class="page-link" href="?page={{num}}">{{ num }}</a>
                </li>
            {% elif num > page_obj.number|add:-3 and num < page_obj.number|add:3 %}
            <li class="page-item">
                <a class="page-link" href="?page={{ num }}">{{ num }}</a>
            </li>
            {% endif %}
        {% endfor %}
        {% if page_obj.has_next %}
            <li class="page-item">
                <a class="page-link" href="?page={{ page_obj.next_page_number }}" aria-label="next">
                    <span aria-hidden="true">&raquo;</span>
                </a>

            </li>
            <li class="page-item">
                <a class="page-link" href="?page={{ page_obj.paginator.num_page }}" aria-label="last">
                    <span aria-hidden="true">&laquo;&lsaquo;</span>
                </a>

            </li>
            {% endif %}
    </ul>
</nav>

{% endblock %} 